﻿@using System.Linq
@using MrCMS.Helpers
@model MrCMS.Web.Areas.Admin.Models.PostingsModel


<div data-paging-type="async">
    @Html.LabelFor(model => model.Search)
    <div class="input-group">
        @Html.TextBoxFor(webpage => webpage.Search, new { @class = "form-control" })
        <span class="input-group-btn">
            <button class="btn btn-default" id="search-postings" data-action="update" data-url="@Url.Action("Postings", new { id = Model.Id })">@Resource("Admin Form Postings Search Button", "Search")</button>
        </span>
    </div>
    <br />
    @if (Model.Items.Any())
    {
        <table class="table table-condensed table-striped">
            <thead>
                <tr>
                    @foreach (var heading in Model.Headings)
                    {
                        <th>
                            @heading
                        </th>
                    }
                    <th>@Resource("Admin Form Postings Posted On", "Posted On")</th>
                    <th>@Resource("Admin Form Postings Actions", "Actions")</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var posting in Model.Items)
                {
                    <tr>
                        @foreach (var heading in Model.Headings)
                        {
                            <td>
                                @if (posting.Get(heading) != null && posting.Get(heading).IsFile)
                                {
                                    <a href="@posting.Get(heading).Value">@Resource("Admin Form Postings Download", "Download")</a>
                                }
                                else
                                {
                                    @posting[heading].TruncateString(200)
                                }
                            </td>
                        }
                        <td>
                            @posting.CreatedOn
                        </td>
                        <td>
                            <div class="btn-group">
                                @Html.ActionLink(Resource("Admin Form Postings View full entry", "View full entry"), "ViewPosting", new { id = posting.Id }, new { @class = "btn btn-default btn-xs", data_toggle = "fb-modal" })

                                @Html.ActionLink(Resource("Delete"), "DeleteEntry", "Form", new { id = posting.Id }, new { @class = "btn btn-xs btn-danger", data_toggle = "fb-modal" })
                            </div>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
        @Html.Pager(Model.Items, "Postings", i => new { Model.Id, page = i, Model.Search })
    }
    else
    {
        <span>@Resource("Admin Form Postings no postings found", "No postings found.")</span>
    }
</div>
